#!/bin/sh
fail=0

# 'chronic' only displays output in case of a non-zero exit status. It comes
# from the 'moreutils' package, so it's not always available.
chronic=$( which chronic )
if [ $? -ne 0 ]; then
    chronic=
fi

for hook in hooks/pre-commit-*; do
    if [ -x $hook ]; then
        echo "Running $hook..."
        $chronic $hook
        status=$?
        if [ $status -ne 0 ]; then
            echo "$hook failed with status $status"
            fail=1
        fi
    else
        echo "WARNING: Skipping $hook since it's not executable."
    fi
done
exit $fail
